//
//  JYJProgramTableViewCell.m
//  HappyListen
//
//  Created by 冀永金 on 16/8/31.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJProgramTableViewCell.h"
#import "BaseCollectionView.h"
#import "BaseLabel.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "JYJTAMacro.h"
#import "BaseButton.h"
#import "JYJProgramModel.h"
#import "JYJBestItemsModel.h"
@interface JYJProgramTableViewCell ()
@property (nonatomic, strong) UIImageView *backImage;
@property (nonatomic, strong) UIImageView *backImageTwo;
@property (nonatomic, strong) UIView *redView;
@property (nonatomic, strong) BaseLabel *titleLabel;

@property (nonatomic, strong) UIImageView *musicImage;
@property (nonatomic, strong) UIImageView *playCountImage;
@property (nonatomic, strong) BaseLabel *playCountLabel;
@property (nonatomic, strong) UIImageView *praiseImage;
@property (nonatomic, strong) BaseLabel *praiseLabel;
@property (nonatomic, strong) UIImageView *commentImage;
@property (nonatomic, strong) BaseLabel *commentLabel;
@property (nonatomic, strong) UIImageView *timeImage;
@property (nonatomic, strong) BaseLabel *timeLabel;


@end
@implementation JYJProgramTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews {
    self.redView = [[UIView alloc]init];
    [self.contentView addSubview:_redView];
    _redView.backgroundColor = [UIColor colorWithRed:0.83 green:0.15 blue:0.11 alpha:1.00];
    self.musicImage = [[UIImageView alloc]init];
    [self.contentView addSubview:_musicImage];
    self.backImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"find_cat_cover"]];
    self.backImage.userInteractionEnabled = YES;
    [self.contentView addSubview:_backImage];
    self.backImageTwo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"catinfo_item_bg"]];
    self.backImageTwo.userInteractionEnabled = YES;
    [self.contentView addSubview:_backImageTwo];
    self.titleLabel = [[BaseLabel alloc]init];
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_titleLabel];
    self.playCountImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"catinfo_play_cnt"]];
    [self.contentView addSubview:_playCountImage];
    self.playCountLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_playCountLabel];
    
    _playCountLabel.font = [UIFont systemFontOfSize:13];
    _playCountLabel.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    self.praiseImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"search_music_info1"]];
    [self.contentView addSubview:_praiseImage];
    self.praiseLabel = [[BaseLabel alloc]init];
    self.praiseLabel.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    _praiseLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:_praiseLabel];
    self.commentImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"search_music_info3"]];
    [self.contentView addSubview:_commentImage];
    self.commentLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_commentLabel];
    _commentLabel.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    _commentLabel.font = [UIFont systemFontOfSize:13];
    self.timeImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"catinfo_time"]];
    [self.contentView addSubview:_timeImage];
    self.timeLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_timeLabel];
    _timeLabel.font = [UIFont systemFontOfSize:13];
    _timeLabel.textColor = [UIColor colorWithRed:0.49 green:0.49 blue:0.52 alpha:1.00];
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(44);
        make.width.mas_equalTo(2);
        make.height.mas_equalTo(self.contentView.bounds.size.height - 80);
    }];
    [self.backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(5);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(80);
    }];
    [self.musicImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-15);
        make.left.equalTo(self.contentView.mas_left).with.offset(20);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    self.musicImage.layer.cornerRadius = 25;
    self.musicImage.clipsToBounds = YES;
    [self.backImageTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(10);
        make.left.equalTo(self.backImage.mas_right).with.offset(15);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.height.mas_equalTo(90);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(10);
        make.left.equalTo(self.backImage.mas_right).with.offset(50);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(SCREEN_WIDTH - 200);
    }];
    [self.playCountImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(72);
        make.left.equalTo(self.backImage.mas_right).with.offset(50);
        make.height.mas_equalTo(10);
        make.width.mas_equalTo(10);
    }];
    [self.playCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(70);
        make.left.equalTo(self.playCountImage.mas_right).with.offset(5);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(40);

    }];
    [self.praiseImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(72);
        make.left.equalTo(self.playCountLabel.mas_right).with.offset(10);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(12);
    }];
    [self.praiseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(70);
        make.left.equalTo(self.praiseImage.mas_right).with.offset(5);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(30);
    }];
    [self.commentImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(72);
        make.left.equalTo(self.praiseLabel.mas_right).with.offset(10);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(12);
    }];
    [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(70);
        make.left.equalTo(self.commentImage.mas_right).with.offset(5);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(30);
    }];
    [self.timeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(72);
        make.left.equalTo(self.commentLabel.mas_right).with.offset(10);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(12);

    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.with.offset(70);
        make.left.equalTo(self.timeImage.mas_right).with.offset(5);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(40);
    }];
    
}
- (void)setProgramModel:(JYJProgramModel *)programModel {
    _programModel = programModel;
    [self.musicImage sd_setImageWithURL:[NSURL URLWithString:programModel.music_img] placeholderImage:PLACEHOLDERIMAGE];
    self.titleLabel.text = programModel.music_title;
    self.playCountLabel.text = [NSString stringWithFormat:@"%ld",programModel.music_views];
    self.praiseLabel.text = [NSString stringWithFormat:@"%ld",programModel.music_recomms];
    self.commentLabel.text = [NSString stringWithFormat:@"%ld",programModel.music_comments];
    self.timeLabel.text = [NSString stringWithFormat:@"%ld:%ld",programModel.music_duration / 60,programModel.music_duration % 60];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
